package com.hp.goods_service.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ的配置
 */
@Configuration
public class RabbitMQConfig {

    public static final String QUEUE_GOODS_SAVE = "queue.goods.save";
    public static final String QUEUE_GOODS_UPDATE = "queue.goods.update";
    public static final String QUEUE_GOODS_REMOVE = "queue.goods.remove";
    public static final String KEY_GOODS_SAVE = "key.goods.save";
    public static final String KEY_GOODS_UPDATE = "key.goods.update";
    public static final String KEY_GOODS_REMOVE = "key.goods.remove";

    public static final String GOODS_EXCHANGE = "goods.exchange";

    @Bean
    public Queue queueGoodsSave(){
        return new Queue(QUEUE_GOODS_SAVE);
    }

    @Bean
    public Queue queueGoodsUpdate(){
        return new Queue(QUEUE_GOODS_UPDATE);
    }

    @Bean
    public Queue queueGoodsRemove(){
        return new Queue(QUEUE_GOODS_REMOVE);
    }

    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(GOODS_EXCHANGE);
    }

    @Bean
    public Binding bindGoodsSave(){
        return BindingBuilder.bind(queueGoodsSave()).to(topicExchange()).with(KEY_GOODS_SAVE);
    }

    @Bean
    public Binding bindGoodsUpdate(){
        return BindingBuilder.bind(queueGoodsUpdate()).to(topicExchange()).with(KEY_GOODS_UPDATE);
    }

    @Bean
    public Binding bindGoodsRemove(){
        return BindingBuilder.bind(queueGoodsRemove()).to(topicExchange()).with(KEY_GOODS_REMOVE);
    }
}
